#pragma once
#include"Stack.h"
void StackInit(ST* ps)
{
	assert(ps);
	ps->data = NULL;
	ps->capacity = 0;
	ps->top = 0;
}
void StackDestroy(ST* ps)
{
	assert(ps);
	free(ps->data);
	ps->data = NULL;
	ps->capacity = 0;
	ps->top = 0;
}
void StackPush(ST* ps, STDataType x)
{
	assert(ps);
	if (ps -> top == ps->capacity)
	{
		int newcapacity = (ps->capacity == 0) ? 4 : 2 * ps->capacity;
		ps->data = (STDataType*)realloc(ps->data,sizeof(STDataType) * newcapacity);
		if (ps->data == NULL)
		{
			printf("realloc fail\n");
			exit(-1);
		}
		ps->capacity = newcapacity;
	}
	ps->data[ps->top++] = x;
}
STDataType StackTop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	return ps->data[ps->top - 1];
}
void StackPop(ST* ps)
{
	assert(ps);
	assert(ps->top > 0);
	ps->data[ps->top - 1] = 0;
	ps->top--;
}
int StackSize(ST* ps)
{
	assert(ps);
	return ps->top;
}
bool StackEmpty(ST* ps)
{
	assert(ps);
	return ps->top == 0;
}